package com.rado.tf.gui;

import com.rado.tf.gui.navigation.NavigationPlugin;
import com.rado.tf.gui.view.application.impl.ApplicationViewImpl;
import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.ui.themes.ChameleonTheme;
import org.springframework.context.ApplicationContext;

/**
 * Created by parado on 14.03.14.
 */
@Theme(ChameleonTheme.THEME_NAME)
public class MainUI extends UI
{
   private transient ApplicationContext uiContext;

   public void setUiContext(ApplicationContext uiContext)
   {
      this.uiContext = uiContext;
   }

   public ApplicationContext getUiContext()
   {
      return uiContext;
   }

   @Override
   protected void init(VaadinRequest request)
   {
      NavigationPlugin navigationPlugin = (NavigationPlugin) uiContext.getBean(NavigationPlugin.BEAN_NAME);
      navigationPlugin.init();
      setContent((Component) uiContext.getBean(ApplicationViewImpl.BEAN_NAME));
   }

   public static MainUI get()
   {
      return (MainUI) getCurrent();
   }
}
